package com.taiyi.renaissancemall.ui.mine.order.order_sale_list;

import android.content.Intent;

import com.taiyi.renaissancemall.Utils.ToastUtils;
import com.taiyi.renaissancemall.Utils.Utils;
import com.taiyi.renaissancemall.base.BasePresent;
import com.taiyi.renaissancemall.base.MyApp;
import com.taiyi.renaissancemall.bean.BaseResultBean;
import com.taiyi.renaissancemall.bean.EmptyBean;
import com.taiyi.renaissancemall.bean.OrderListBean;
import com.taiyi.renaissancemall.net.BaseUrl;
import com.taiyi.renaissancemall.net.HttpUtils;
import com.taiyi.renaissancemall.net.callbck.JsonCallback;
import com.taiyi.renaissancemall.ui.login.LoginActivity;
import com.taiyi.renaissancemall.ui.mine.order.delivered.DeliveredView;

import java.util.HashMap;
import java.util.Map;

import okhttp3.Response;

public class SalePresent extends BasePresent<SaleView> {

    public void getOrderList() {
        Map<String, String> map = new HashMap<>();
        map.put("pagenum", "1");
        map.put("ordertype", "-2");
        HttpUtils.postRequest(BaseUrl.GET_ORDER_LIST, this, map, new JsonCallback<BaseResultBean<OrderListBean>>() {
            @Override
            public BaseResultBean<OrderListBean> convertResponse(Response response) throws Throwable {
                return super.convertResponse(response);
            }

            @Override
            public void onSuccess(com.lzy.okgo.model.Response<BaseResultBean<OrderListBean>> response) {
                super.onSuccess(response);
                if (response.body().code == 0) {
                    view.getOrderListSuccess(response.body().data);
                } else if (response.body().code == -1) {
                    Utils.getSpUtils().remove("token");
                    MyApp.getInstance().startActivity(new Intent(MyApp.getInstance(), LoginActivity.class));
                } else {
                    view.getOrderListFailure(response.body().msg_cn);
                }
            }

            @Override
            public void onError(com.lzy.okgo.model.Response<BaseResultBean<OrderListBean>> response) {
                super.onError(response);
            }
        });
    }

    public void remind() {
        Map<String, String> map = new HashMap<>();
        map.put("ordercommodityid", view.getOrderId());
        HttpUtils.postRequest(BaseUrl.REMIND, this, map, new JsonCallback<BaseResultBean<EmptyBean>>() {
            @Override
            public BaseResultBean<EmptyBean> convertResponse(Response response) throws Throwable {
                return super.convertResponse(response);
            }

            @Override
            public void onSuccess(com.lzy.okgo.model.Response<BaseResultBean<EmptyBean>> response) {
                super.onSuccess(response);
                if (response.body().code == 0) {
                    ToastUtils.showLongToast(response.body().msg_cn);
                    view.remindSuccess();
                } else if (response.body().code == -1) {
                    Utils.getSpUtils().remove("token");
                    MyApp.getInstance().startActivity(new Intent(MyApp.getInstance(), LoginActivity.class));
                } else {
                    view.remindFailure(response.body().msg_cn);
                }

            }

            @Override
            public void onError(com.lzy.okgo.model.Response<BaseResultBean<EmptyBean>> response) {
                super.onError(response);
            }
        });
    }
}
